<!DOCTYPE html>
<html lang="zn-CH">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Classes</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
    <h1>Classes</h1>
    {% if role == 'student' %}
    <a href="{{ url_for('classes.new_class') }}">加入班级</a>
    {% else %}
    <a href="{{ url_for('classes.new_class') }}">开设班级</a>
    {% endif %}
    <table>
        <tr>
            <th>课程序号</th>
            {% if role == 'teacher' %}
            <th>课程码</th>
            {% endif %}
            <th>Name</th>
            <th>Course</th>
            <th>Teacher</th>
            <th>Actions</th>
        </tr>
        {% for class in classes %}
        <tr>
            <td>{{ loop.index }}</td>
            {% if role == 'teacher' %}
            <td>{{ class.id }}</td>
            {% endif %}
            <td>
                <a href="{{ url_for('classes.class_dashboard', id=class.id, role=role) }}">
                    {{ class.name }}
                </a>
            </td>
            <td>{{ class.course_name }}</td>
            <td>{{ class.teacher_name }}</td>
            <td>
                {% if role == 'student' %}
                <form action="{{ url_for('classes.leave_class', id=class.id) }}" method="post" style="display:inline;">
                    <button type="submit">退出班级</button>
                </form>
                {% elif role == 'teacher' %}
                <form action="{{ url_for('classes.delete_class', id=class.id) }}" method="post" style="display:inline;">
                    <button type="submit">解散班级</button>
                </form>
                {% else %}
                    <p>Welcome! Please log in to see more options.</p>
                {% endif %}

            </td>
        </tr>
        {% endfor %}
    </table>
    <a href="/dashboard" class="btn btn-secondary">返回</a>
</body>
</html>
